package com.yhsimon.realm.member.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yhsimon.realm.member.entity.user.BeanBillEntity;
import com.yhsimon.realm.member.entity.user.LoginRecordEntity;
import com.yhsimon.realm.member.service.BeanBillService;
import com.yhsimon.realm.member.service.BeanService;
import com.yhsimon.realm.member.utils.R;
import com.yhsimon.realm.member.vo.user.BeanBillVo;
import com.yhsimon.realm.member.vo.user.BeanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/member/bean")
public class BeanController {

    @Autowired
    private BeanService beanService;

    @Autowired
    private BeanBillService beanBillService;

    @GetMapping("/getBeanByUserId/{userId}")
    public R getBeanByUserId(@PathVariable String userId) {
        BeanVo beanVo = beanService.getBeanByUserId(Long.parseLong(userId));
        return R.ok().put("data", beanVo);
    }

    @GetMapping("/getBeanBillByUserId")
    public R getBeanBillByUserId(@RequestParam(defaultValue = "1") int page, @RequestParam(defaultValue = "5") int size, @RequestParam("userId") String userId) {
        long totalCount = beanBillService.count(new QueryWrapper<BeanBillEntity>().eq("user_id", userId));
        List<BeanBillVo> beanBillVoList = beanService.getBeanBillByUserId(page, size,Long.parseLong(userId));
        Map<String, Object> map = new HashMap<>();
        map.put("totalCount", totalCount);
        map.put("beanBillList", beanBillVoList);
        return R.ok().put("data", map);
    }
}
